//
//  CategorySKUViewController.m
//  Tang
//
//  Created by 352324497@qq.com on 15/12/7.
//  Copyright © 2015年 352324497@qq.com. All rights reserved.
//

#import "CategorySKUViewController.h"
#import "CategorySKUCell.h"
#import "SKUDetailController.h"
@interface CategorySKUViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong)NSMutableArray *modelArray;
@end

@implementation CategorySKUViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 30 * Kx6, KWidth, KHeight - 100 * Kx6) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor colorWithRed:240 / 255.0 green:240 / 255.0 blue:240 / 255.0 alpha:1];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerClass:[CategorySKUCell class] forCellWithReuseIdentifier:@"cell"];
    [self.view addSubview:_collectionView];
    
    
   // NSLog(@"sku == %ld", self.SKUModelArray.count);
}
#pragma mark - collection
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.SKUModelArray.count != 0)
    {
        if (self.modelArray.count != 0)
        {
            return self.SKUModelArray.count + self.modelArray.count;
        }
        return self.SKUModelArray.count;
    }
    return 0;
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10 * Kx6, 10 * Kx6, 10 * Kx6, 10 * Kx6);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.SKUModelArray.count != 0)
    {
        return CGSizeMake((KWidth - 32 * Kx6) / 2, (KWidth - 32 * Kx6) / 2 + 50 * Kx6);
    }
    return CGSizeMake(0, 0);
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CategorySKUCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (self.SKUModelArray.count != 0)
    {

        CategorySKUModel *model = self.SKUModelArray[indexPath.item];
        cell.model = model;
        cell.backgroundColor = [UIColor whiteColor];
        cell.layer.cornerRadius = 5 * Kx6;
    }
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    CategorySKUModel *model = self.SKUModelArray[indexPath.item];
    SKUDetailController *SKU = [[SKUDetailController alloc]init];
    SKU.ID = model.ID;
    [self.navigationController pushViewController:SKU animated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
